<?php
namespace app\msgapi\controller;

use app\BaseController;
use app\msgapi\service\HsorganizationService;
use app\Request;

/**
 * 企业组织架构控制器
 */
class Hsorganization extends BaseController
{
    protected HsorganizationService $service;
    public function __construct(HsorganizationService $service)
    {
        parent::__construct(app());
        $this->service = $service;
    }

    /**获取指定部门成员(带聊天统计、客户统计信息)列表
     * @param Request $request
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getDeparmentMembersChatCustLst(Request $request)
    {
        $data = $request->only(['department_id','page','limit','name','start_time','end_time']);
        return $this->service->getDeparmentMembersChatCustLst($data,$request->admin_groupid,$request->adminid);
    }

    /**获取所有企业成员
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getAllUser()
    {
        return $this->service->getAllUser();
    }

    /**员工统计列表
     * @return \think\response\Json
     */
    public function getStaffLst(Request $request)
    {
        $data = $request->only(['page','limit','name','start_time','end_time']);
        return $this->service->getStaffLst($data);
    }

    /**手动同步成员、部门
     * @param Request $request
     * @return \think\response\Json
     */
    public function syncContacts(Request $request)
    {
        $data = $request->only(['is_ok'],'post');
        return $this->service->syncContacts($data);
    }

    /**全量获取部门、成员信息
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getDepartmentLst(Request $request)
    {
        //ispermit:是否仅获取监管成员 1是 0否|getuser:是否获取成员 1是 0否
        $data = $request->only(['ispermit'=>0,'getuser'=>1],'post');
        return $this->service->getDepartmentLst($data['getuser'],$data['ispermit'],$request->admin_groupid,$request->adminid);
    }

    /**获取指定部门成员
     * @return \think\response\Json
     */
    public function getDeparmentMembers(Request $request)
    {
        $data = $request->only(['department_id','page','limit','order','sort'],'post');
        return $this->service->getDeparmentMembers($data,$request->admin_groupid,$request->adminid);
    }

    /**获取所有被监管成员
     * @param Request $request
     * @return \think\response\Json
     * @throws \think\db\exception\DbException
     */
    public function getPermitLst(Request $request)
    {
        $data = $request->only(['page','limit','order','sort','name'], 'post');
        return $this->service->getPermitLst($data, $request->admin_groupid, $request->adminid);
    }

    /**根据userid获取成员或者客户信息(名片消息用)
     * @param Request $request
     * @return \think\response\Json
     */
    public function getUserOrCustInfo(Request $request)
    {
        $data = $request->only(['userid'],'post');
        return $this->service->getUserOrCustInfo($data);
    }


    /**侧边栏获取客户会话对象列表
     * @param Request $request
     * @return \think\response\Json
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getCustMessageObj(Request $request)
    {
        $data = $request->only(['page','limit','external_userid','is_crowd','searchname'],'post');
        return $this->service->getCustMessageObj($data,$request->admin_groupid,$request->adminid);
    }

    /**启用企业成员
     * @param Request $request
     * @return \think\response\Json
     * @throws \Exception
     */
    public function enableCorpUser(Request $request)
    {
        $data = $request->only(['userid'],'post');
        return $this->service->enableCorpUser($data);
    }


}